<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生注册 - 校园点餐系统</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; padding: 40px 0; }
        .register-card { max-width: 500px; margin: 0 auto; }
    </style>
</head>
<body>
    <div class="container">
        <div class="register-card">
            <div class="card shadow-lg">
                <div class="card-body p-5">
                    <div class="text-center mb-4">
                        <h3>学生注册</h3>
                        <p class="text-muted">加入我们，开始点餐</p>
                    </div>
                    <form id="registerForm">
                        <div class="mb-3">
                            <label class="form-label">学号</label>
                            <input type="text" class="form-control" name="studentId" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">用户名</label>
                            <input type="text" class="form-control" name="username" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">真实姓名</label>
                            <input type="text" class="form-control" name="realName" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">手机号</label>
                            <input type="tel" class="form-control" name="phone" pattern="[0-9]{11}" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">密码</label>
                            <input type="password" class="form-control" name="password" minlength="6" required>
                        </div>
                        <div class="row mb-3">
                            <div class="col-6">
                                <label class="form-label">院系</label>
                                <input type="text" class="form-control" name="department" required>
                            </div>
                            <div class="col-6">
                                <label class="form-label">专业</label>
                                <input type="text" class="form-control" name="major" required>
                            </div>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">宿舍</label>
                            <input type="text" class="form-control" name="dormitory" placeholder="例如：1号楼101" required>
                        </div>
                        <button type="submit" class="btn btn-primary w-100 mb-3">注册</button>
                        <div class="text-center">
                            <span class="text-muted">已有账号？</span>
                            <a href="/user/login">立即登录</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
    <script>
        $(document).ready(function() {
            $('#registerForm').submit(function(e) {
                e.preventDefault();
                
                $.ajax({
                    url: '/api/auth/user/register',
                    type: 'POST',
                    contentType: 'application/json',
                    data: JSON.stringify({
                        studentId: $('input[name="studentId"]').val(),
                        username: $('input[name="username"]').val(),
                        realName: $('input[name="realName"]').val(),
                        phone: $('input[name="phone"]').val(),
                        password: $('input[name="password"]').val(),
                        department: $('input[name="department"]').val(),
                        major: $('input[name="major"]').val(),
                        dormitory: $('input[name="dormitory"]').val()
                    }),
                    success: function(res) {
                        if (res.code === 200) {
                            alert('注册成功！请登录');
                            window.location.href = '/user/login';
                        } else {
                            alert(res.message);
                        }
                    },
                    error: function(xhr) {
                        alert(xhr.responseJSON?.message || '注册失败');
                    }
                });
            });
        });
    </script>
</body>
</html>

